<#import "/spring.ftl" as spring />
<#import "/inspector-time-macros.ftl" as imacro />

<html>
<head>
	<title>addEditRecurringRule.ftl</title>
</head>

<body>

<div id="content">

	<#if command.id??>
		<#assign mode="edit" />
	<#else>
		<#assign mode="add" />
	</#if>
	
	<#if mode == "edit">
		<h1>EDIT RECURRING TIMESLOT</h1>
		
		<p>Your current recurring timeslot details:</p>
		
		<p>
		<#-- assign a new var name so we can use the common "details" include -->
		<#assign scheduleRule = command />
		<#include "/inspector/scheduleRule/include-scheduleRuleDetails.ftl" />
		</p>
		
		<p>
		Editing this timeslot will modify ALL future timeslots based on this rule. 
		</p>
	<#else>
		<h1>ADD RECURRING TIMESLOT</h1>
		
		<p>A recurring timeslot allows you to specify a period of time that you're available (or unavailable) for an inspection on particular day(s) of the week, and will continue indefinitely.</p>
	</#if>
	
	<@imacro.listErrors "command" />
	
	<#if mode == "edit">
		<form method="post" method="editRecurringRule.html">
	<#else>
		<form method="post" method="addRecurringRule.html">
	</#if>
	
	<input type="hidden" name="frequencyType" value="DAY_OF_WEEK" />
	
	<div class="databoxWrapper">
		<div class="databox">
		<h1>TIMESLOT DETAILS</h1>
			<table class="databoxLabelTable2Cols">
			<tr>
				<th>START TIME:</td>
				<td class="databoxFreeForm"><@spring.formSingleSelect "command.startHour", hours/>:<@spring.formSingleSelect "command.startMinute", minutes/></td>
			</tr>
			<tr>
				<th>END TIME:</td>
				<td class="databoxFreeForm"><@spring.formSingleSelect "command.endHour", hours/>:<@spring.formSingleSelect "command.endMinute", minutes/></td>
			</tr>
			<#--tr>
				<th>ARE YOU AVAILABLE IN THIS TIMESLOT?</td>
				<td><@imacro.singleRadioButton "command.available"," YES" " NO" "&nbsp;&nbsp;" "class=radio"/></td>
			</tr-->
		</table>
		
		<table class="databoxLabelTable">
			<tr>
				<td>
					<b>DAY(S) OF WEEK TO APPLY TIMESLOT:</b>
					
					<p></p> <!-- stupid -->
					
					<#-- couldn't make the spring checkbox tag work with Integers in the hashmap,
							so have to do it by hand -->
						<#assign keys = daysOfWeek?keys>
						<@spring.bind "command.units" /> 
							<#list keys as key>
								<li style="padding: 3px; display: inline"><input type="checkbox" name="${spring.status.expression}" value="${key}" class="checkbox"
								<#list command.units as ruleUnit>
									<#if ruleUnit?string == key>checked</#if>
								</#list>
								> ${daysOfWeek[key]}
								
							</#list>			
						</ul>
				</td>
			
			</tr>
		</table>
		
		</div>
	</div>
	
	<#if mode == "edit">
	    <input type="submit" value="SAVE TIMESLOT" class="formButton"/>&nbsp;&nbsp;&nbsp;<a href="deleteScheduleRule.html?inspectorId=${RequestParameters.inspectorId}&ruleId=${command.id}" class="formLink">-DELETE TIMESLOT-</a>&nbsp;&nbsp;&nbsp;<a href="viewScheduleRules.html?inspectorId=${RequestParameters.inspectorId}" class="formLink">-CANCEL-</a>
	    
	<#else>
		<input type="submit" value="ADD TIMESLOT" class="formButton"/>
	</#if>
	
	</form>

</div>
</body>
</html>